using System;
using System.Collections.Generic;
using System.Text;

namespace IRCEngine
{
	public sealed class Params : MarshalByRefObject
	{
		private String[] parametres;

		public int Count
		{
			get
			{
				return parametres.Length;
			}
		}

		public String this[int index]
		{
			get
			{
				return parametres[index];
			}
		}

		public bool HasTrailingParam { get; private set; }

		public String TrailingParam
		{
			get
			{
				return parametres[parametres.Length - 1];
			}
		}

		public Params(String parametres)
		{
			List<String> discovered = new List<String>();
			int position = 0;
			while (position < parametres.Length)
			{
				int delimiteur = parametres.IndexOf(' ', position);
				if (delimiteur == -1)
					delimiteur = parametres.Length;
				if ((parametres[position] == ':')
					&& (position + 1 < parametres.Length))
				{
					HasTrailingParam = true;
					discovered.Add(parametres.Substring(position + 1));
					position = parametres.Length;
				}
				else
				{
					discovered.Add(parametres.Substring(position, delimiteur - position));
					position = delimiteur + 1;
				}
			}
			this.parametres = discovered.ToArray();
		}
	}
}
